// 这个页面api都会绑定到全局变量$api上
import http from '@/api/http.js'

import {getType} from '@/utils/index.js'

const arr = [
  "admin/post_c_bug",
  "jsmind/get_minds",
  "jsmind/get_mind",
  "jsmind/post_mind",
  "jsmind/del_mind",
  "jsmind/put_mind_limit",
  "admin/del_im_file",
  "admin/get_authors",
  "admin/get_note_bug_apis",
  "common/get_errs",
  "blog/get_notes",
  "ac_admin/get_ac_list",
  "admin/get_c_bugs",
  "common/post_temporary",
  "common/put_options",
  "others/post_electric_charge",
  "others/get_electric_charges",
  "others/del_ctric_charges",
  "author/get_monitors",
  "author/get_monitor_echarts",
  "game/get_im_rooms",
  "game/get_chat_list",
  "game/get_im_room_remmbers",
  "game/del_im_sys",
  "common/get_emoji_class",
  "common/get_emojis",
  "admin/get_codes",
  "admin/get_comments",
  "blog/get_blog_tag_list",
  "admin/get_push_tasks",
  "author/get_weights",
  "author/put_author",
  "admin/get_send_msgs",
  "admin/post_send_msg",
  "admin/del_send_msg",
  "blog/get_month_notes",
  "common/post_file",
  "common/get_schema",
  "bn/post_create_pdf",
  "bn/get_first_stages",
  "bn/post_first_stage",
  "bn/del_first_stage",
  "bn/get_bn_moban_list",
  "bn/get_bn_moban",
  "bn/post_bn_moban",
  "bn/del_bn_moban",
  "bn/get_bn_user_list",
  "bn/get_bn_user",
  "bn/post_bn_user",
  "bn/del_bn_user",
  "bn/post_bn_partial_update",
  "bn/get_bn_statisticscs",
  "bn/del_bn_statisticsc",
  "bn/get_moban_first_stages",
  "author/get_day_push_tasks",
  "common/get_about_me",
  "common/post_about_me",
  "common/get_options",
  "admin/get_notes_list_echarts",
  "blog/post_note",
  "blog/put_note",
  "common/get_code",
  "blog/get_mobile_home_list",
  "author/get_author_read_history",
  "blog/put_article_class",
  "author/post_author_read_history",
  "blog/post_collection_articles",
  "blog/delete_collection_article",
  "blog/del_comment",
  "blog/put_comment",
  "blog/post_comment",
  "author/put_userinfo",
  "blog/get_collection_articles",
  "author/post_user_sync",
  "common/get_img",
  "common/get_imgs",
  "game/get_games",
  "game/post_game",
  "game/del_game",
  "game/post_game_sort",
  "game/get_room",
  "game/post_im_room",
  "game/del_im_room",
  "game/get_im_room_member",
  "game/post_im_room_member",
  "game/get_gobang",
  "game/get_gobang_list",
  "author/post_author_fly",
  "blog/get_note",
  "blog/get_article_by_tagids",
  "admin/delete_note_bug_api",
  "admin/post_note_bug_api",
  "admin/put_note_bug_api",
  "blog/get_export_notes",
  "common/del_errs",
  "admin/delete_push_task",
  "admin/post_push_task",
  "author/put_author_config",
  "admin/delete_code",
  "admin/del_c_bug",
  "admin/del_blog_imgs",
  "common/put_emoji",
  "common/del_emoji",
  "common/get_tags",
  "common/del_tag",
  "common/post_tag",
  "author/delete_weight",
  "author/post_weight",
  "blog/delete_blog_tag",
  "blog/post_blog_tag",
  "admin/delete_plugin",
  "admin/put_plugin",
  "admin/get_plugins",
  "admin/post_plugin",
  "blog/get_mobile_user_info",
  "low_code/get_low_code_syss",
  "low_code/post_low_code_sys",
  "low_code/del_low_code_sys",
  "low_code/get_low_code_pages",
  "low_code/get_low_code_page",
  "low_code/post_low_code_page",
  "low_code/del_low_code_page",
  "author/get_author_fly_visual",
  "common/get_common_imgs",
  "common/post_common_imgs",
  "common/del_common_imgs",
  "blog/get_blog_tables",
  "blog/post_table",
  "blog/delete_table",
  "admin/get_week_plans",
  "admin/del_week_plan",
  "admin/post_week_plan",
  "common/get_festivals",
  "common/del_festival",
  "common/post_festival",
  {
    // 支持对象配置，取第一个为methods
    get_classs: "blog/classs",
    get_net_dists: "common/getNetdists",
    post_Netdist: "common/postNetdist",
    get_ceshi: "ceshi",
    del_note: "blog/delete_note",
    post_login: "author/login",
    get_a: "/api/a",
    get_click_ranking: "blog/click_ranking",
    get_recent_updates: "blog/recent_updates",
    get_searchArticles: "blog/searchArticles",
    get_article: "blog/article",
    get_articles: "blog/articles",
    del_article: "blog/delarticle",
    post_replay_comment: "blog/replay_comment",
    post_addarticle: "blog/addarticle",
    put_putarticle: "blog/putarticle",
    get_im_heart: "game/im_heart",
    get_blog_comments: "blog/get_comments",
    get_day_init: "common/day_init",
    del_ac_page: "ac_admin/ac_page",
    put_putclass: "blog/putclass",
    post_addclass: "blog/addclass",
    del_delclasss: "blog/delclass",
    get_ac_page: "ac_admin/ac_page",
    post_ac_page: "ac_admin/ac_page",
    put_putNetdist: "common/putNetdist",
  },
];

const APIS = {}
const obj1 = {
    get: 'GET',
    post: 'POST',
    put: 'PUT',
    del: 'DELETE',
}

arr.forEach((item) => {
    if (getType(item) === 'object') {
        Object.keys(item).forEach((key) => {
            if(APIS[key]){
                Toast(`${key}已存在，请检查`)
                return
            }
            APIS[key] = (data) => {
                const method = obj1[key.split('_')[0].toLowerCase()]
                let obj2 = {
                    url: item[key],
                    method,
                }

                if (method == 'GET') {
                    obj2.params = data
                } else {
                    obj2.data = data
                }

                return http(obj2)
            }
        })

        return
    }
    // 按/截取
    let arr1 = item.split('/') || []
    const apiName = arr1[1] || ''
    if(APIS[apiName]){
        Toast(`${apiName}已存在，请检查`)
        return
    }
    // 按_截取
    let arr2 = apiName.split('_')

    const method = obj1[arr2[0].toLowerCase()]

    APIS[apiName] = (data) => {
        let obj2 = {
            url: item,
            method,
        }

        if (method == 'GET') {
            obj2.params = data
        } else {
            obj2.data = data
        }

        return http(obj2)
    }
})

export default APIS